package main

import (
	"encoding/json"
	"fmt"
	"github.com/gin-gonic/gin"
	"github.com/gosnmp/gosnmp"
	"net/http"
	"time"
)

type TrapEventReq struct {
	ReceiverTime time.Time          `json:"receiverTime"`
	Packet       *gosnmp.SnmpPacket `json:"packet"`
	SourceIp     string             `json:"SourceIp"`
}

func main2() {
	router := gin.Default()
	router.POST("/v1/unitrap/forward", func(context *gin.Context) {
		var requestData TrapEventReq
		if err := context.ShouldBindJSON(&requestData); err != nil {
			context.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
			return
		}

		// 将结构体转换为JSON字符串
		jsonData, err := json.Marshal(requestData)
		if err != nil {
			context.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
			return
		}

		fmt.Println(string(jsonData))

		// 返回JSON字符串
		context.JSON(http.StatusOK, gin.H{"data": string(jsonData)})
	})

	_ = router.Run(":8080")
}
